Until now it seemed strings and functions that return strings did not need parentheses "()" for string concatenation. In general, it looks less busy when the () is left out -- provided it works.
string dq(string str) {
return ("\"" str "\"");
}
void iThoughtStringFunctionsDidNotNeedParentheses() {
ack( dq("DOUBLE QUOTED STRING") );
ack( "Here is a: " dq("DOUBLE QUOTED STRING") " but why is the right quote over here --->" );
ack( "Here is a: " (dq("DOUBLE QUOTED STRING")) " () needed for string functions too?" );
}
// call it:
iThoughtStringFunctionsDidNotNeedParentheses();
SystemAdmin - Tue May 25 19:53:14 EDT 2010 |
Re: Are () needed for string functions too?
This seems to be a known bug (feature?). Citing from Tony Goodman's webpage at smartdxl.com (under "Programming") string s1 = "one" string s2 = "two" print upper(s1) " " s2 "n"
"ONE two"
"ONE TWO"
print (upper(s1)) " " s2 "n"
|
Re: Are () needed for string functions too? Citing from the DXL help:
Left/Right Associativity in a language means, that if you have two operators (in this case concatenation) with the same precendence like A + B - C (+ and - have the same precedence) this can be parsed as (A+B) - C -> left associative or a + (B-C) right associative.
string myString = (name B) " -> " (value B) " and " (someMoreFunction B) "\n"
string MyString = name(B) " -> " value(B) " and " someMoreFunction(B) "\n"
string MyString = name (B " -> " value ( B " and " someMoreFunction ( B "\n" ) ) )
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Are () needed for string functions too? Understanding the rules now, I'll be sure to use () in concatenation situations for predictable results. |
Re: Are () needed for string functions too? Mathias Mamsch - Wed May 26 06:11:01 EDT 2010 Citing from the DXL help:
Left/Right Associativity in a language means, that if you have two operators (in this case concatenation) with the same precendence like A + B - C (+ and - have the same precedence) this can be parsed as (A+B) - C -> left associative or a + (B-C) right associative.
string myString = (name B) " -> " (value B) " and " (someMoreFunction B) "\n"
string MyString = name(B) " -> " value(B) " and " someMoreFunction(B) "\n"
string MyString = name (B " -> " value ( B " and " someMoreFunction ( B "\n" ) ) )
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Golly.
string name(int i) {return i "-int"}
//string name(string s) {return s "-string"}
string value(int i) {return i "-int"}
string someMoreFunction(int i) { return i "-int"}
int B = 45
string MyString = name(B) " -> " value(B) " and " someMoreFunction(B) " yyy"
print "[" MyString "]\n"
MyString = name B " -> " value B " and " someMoreFunction B " yyy"
print "[" MyString "]\n"
|
Re: Are () needed for string functions too? llandale - Wed May 26 16:23:28 EDT 2010 Golly.
string name(int i) {return i "-int"}
//string name(string s) {return s "-string"}
string value(int i) {return i "-int"}
string someMoreFunction(int i) { return i "-int"}
int B = 45
string MyString = name(B) " -> " value(B) " and " someMoreFunction(B) " yyy"
print "[" MyString "]\n"
MyString = name B " -> " value B " and " someMoreFunction B " yyy"
print "[" MyString "]\n"
But I don't think that is a bug, because parenthesis have precedence over concatenation. The problem is DXL is a language full of ambiguities and the Parser has a hard time deciding what is what, especially since it does that before even starting the DXL. The way you use the parentheses is not sufficient: If you do name B A or name (B) A or +name ((B)) A + the result is always the same because the parenthesis only apply to B but not to the ambiguity between concatenation and a function call of name and B. To really use the parentheses for grouping this statement you need to do (name B) A. DXL developers were obviously trying to be creative when introducing a whitespace as a concatenation operator and additionally making parentheses optional for single argument function calls. Now its to late to change it, therefore DXL programmers need to be aware of the ambiguities and for the sake of not only the parser but also other people trying to read their code they should (imho) do (name B) instead of name(B). Regards, Mathias Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |